<?php

namespace app\index\controller;

use think\Db;
use think\Cache;
class Qian extends Common{
	public function index(){
		 
		$vendor = $this->gCache('redis','vendor','vendor', 'domain,accessKeyId');
		$this->assign('ad_url',$this->getAd());
		//$this->assign('vendor','http://'.md5(time().'vendor').'.'.$vendor['domain'].'/chouyao.p'.createrand(3).'html?words='.createrand(5).'&id='.mt_rand(1,20));
		//$this->assign('vendor','http://my168.'.$vendor['domain'].'/chouyao.html?id='.mt_rand(1,20));
		//$this->assign('vendor','http://my168.'.$vendor['domain'].'/chouyao.html?words='.createrand(5).'&id='.mt_rand(1,20));
		//$this->assign('vendor','http://'.md5(time().'vendor').'.'.$vendor['domain'].'/chouyao.html?id='.mt_rand(1,20));
		$this->assign('vendor','http://my168.'.$vendor['domain'].'/chouyao.p'.createrand(3).'html?words='.createrand(5).'&id='.mt_rand(1,20));
		return $this->fetch();
	}
	public function qian($id){
		$qid=$id;
		if(!$jump = cache::store('redis')->get('jump')){
            $jump=Db::name('jump')->where('status',2)->field('domain,appid')->select();
            cache::store('redis')->set('jump',$jump,600);
		}
		shuffle($jump);
        $imp = 'http://'.createrand(4).'.'.$jump[0]['domain'].'/goto/'.$qid.'/'.createrand(12).'?code='.createrand(5);
         
		$data = $this->Dlist($qid);
		$data['timeline'] = array(
				'title'=>'我的命运签：'.$data['name'],
                'link'=>$imp,
			);

		$arrive = $this->gCache('redis', 'arrive', 'arrive','domain');
		$data['url'] = 'http://'.md5(time().'arrive').'.'.$arrive['domain'].'/news/content/'.$qid.'/'.createrand(5);
		
		//取消37，38行注释开启二次分享,并注释34，35行,
		 $ds = ['78.sdhxzy.cn']; 
		$data['url'] = 'http://'.createrand(4).'.'.$ds[0].'/index/qian/share2?qid='.$qid;

		$data['ad_url'] = $this->getAd();
		$this->assign('data', $data);
		return $this->fetch('qian');
	}
	//增加二次分享,把下面47-56行复制到qian.php
//----------------------------------------
	public function share2($qid){
        if(!isset($_SERVER['HTTP_REFERER'])){
            $this->assign('url','http://789.sdhxzy.cn/wc668.html');
            return $this->fetch('gotoso');
        }
        $arrive = $this->gCache('redis', 'arrive', 'arrive','domain');
		$data['url'] = 'http://'.md5(time().'arrive').'.'.$arrive['domain'].'/news/content/'.$qid.'/'.createrand(5);
        $this->assign('data',$data);
        return $this->fetch('share2');
    }
//----------------------------------------
	public function gCache($type, $name, $table, $zduan){
		if(!$data = cache::store($type)->get($name)){
            $data=Db::name($table)->where('status',2)->field($zduan)->find();
            cache::store($type)->set($name,$data,600);
		}
		return $data;
	}
	public function getAd(){
		if(!$ad = cache::store('redis')->get('jeff_ad')){
            $ad=Db::name('ad')->where('status',2)->field('domain')->find();
            cache::store('redis')->set('jeff_ad',$ad,120);
		}
		return $ad['domain'];
	}
	public function jump($qid){
		//$arrive = $this->gCache('redis', 'arrive', 'arrive','domain');
        if(!$arrive = cache::store('redis')->get('arrive')){
            $arrive=Db::name('arrive')->where('status',2)->field('domain')->find();
            cache::store('redis')->set('arrive',$arrive,600);
        }
		 $url= 'http://'.md5(time().'tts').'.'.$arrive['domain'].'/news/content/'.$qid.'/'.createrand(5).'?flag=6';
		//$url = 'http://xi.'.$arrive['domain'].'/news/content/'.$qid.'/'.createrand(5);
        //$url[1] = 'http://wx.ksjx168.com./qian/res/'.$qid;
        //shuffle($url);
        header("Location:".$url);
        exit;
        // $this->assign('url',$url);
        // return $this->fetch('jump');
	}

	public function res($qid,$flag=9){
		if($qid>21){
            $qid =mt_rand(1,20);
        }
		$data=$this->Dlist($qid);
        if(empty($data)){
            exit('error');
        }
		if(!$arrive = cache::store('redis')->get('arrive')){
            $arrive=Db::name('arrive')->where('status',2)->field('domain')->find();
            cache::store('redis')->set('arrive',$arrive,600);
        }
		 $data['url']='http://'.md5(time().'tts').'.'.$arrive['domain'];
		//$data['url']='http://'.mt_rand(1111,99999).'.'.$arrive['domain'];
		if($flag===9){
			$data['flag'] = true;
		}else{
			$data['flag'] = false;
		}
		$data['date'] = date('Y-m-d');
		$data['ad_url'] = $this->getAd();
		$this->assign('data', $data);
		return $this->fetch('res');
	}
    public function Dlist($id){
        $list = [
            ['name'=>'7宫3度','pic'=>'https://img.alicdn.com/imgextra/i2/69145909/O1CN01V8KGaJ1tWMrXr4F9h_!!69145909.jpg'],
            ['name'=>'6宫7度','pic'=>'https://img.alicdn.com/imgextra/i3/69145909/O1CN01tl9gS61tWMrV1Hc4c_!!69145909.png'],
            ['name'=>'6宫9度','pic'=>'https://img.alicdn.com/imgextra/i1/69145909/O1CN01uE9blM1tWMrV1JUTc_!!69145909.png'],
            ['name'=>'5宫7度','pic'=>'https://img.alicdn.com/imgextra/i1/69145909/O1CN01qFGOuK1tWMrWnf67D_!!69145909.png'],
            ['name'=>'6宫3度','pic'=>'https://img.alicdn.com/imgextra/i3/69145909/O1CN01kagaYv1tWMrWoB04j_!!69145909.png'],
            ['name'=>'5宫1度','pic'=>'https://img.alicdn.com/imgextra/i2/69145909/O1CN01jKIRPX1tWMrUGwBqN_!!69145909.png'],
            ['name'=>'5宫3度','pic'=>'https://img.alicdn.com/imgextra/i3/69145909/O1CN01m8wVng1tWMrZ4BMfs_!!69145909.png'],
            ['name'=>'4宫7度','pic'=>'https://img.alicdn.com/imgextra/i3/69145909/O1CN01g7Hj2Y1tWMrWnf60L_!!69145909.png'],
            ['name'=>'4宫3度','pic'=>'https://img.alicdn.com/imgextra/i2/69145909/O1CN01t5Za3j1tWMrXkQdZD_!!69145909.png'],
			['name'=>'3宫6度','pic'=>'https://img.alicdn.com/imgextra/i2/69145909/O1CN01lE4Pcn1tWMrXdl5yD_!!69145909.png'],
			['name'=>'4宫9度','pic'=>'https://img.alicdn.com/imgextra/i4/69145909/O1CN01ivsNUk1tWMrXcaa8T_!!69145909.png'],
			['name'=>'3宫3度','pic'=>'https://img.alicdn.com/imgextra/i1/69145909/O1CN01zpsgWt1tWMrUGwWWJ_!!69145909.png'],
			['name'=>'4宫8度','pic'=>'https://img.alicdn.com/imgextra/i1/69145909/O1CN01GKsrVG1tWMrWo9zcz_!!69145909.png'],
			['name'=>'5宫4度','pic'=>'https://img.alicdn.com/imgextra/i1/69145909/O1CN01HUt6uy1tWMrXccjBd_!!69145909.png'],
			['name'=>'6宫4度','pic'=>'https://img.alicdn.com/imgextra/i2/69145909/O1CN01Q9U2601tWMrWoBKsz_!!69145909.png'],
			['name'=>'5宫7度','pic'=>'https://img.alicdn.com/imgextra/i1/69145909/O1CN01qFGOuK1tWMrWnf67D_!!69145909.png'],
			['name'=>'6宫8度','pic'=>'https://img.alicdn.com/imgextra/i3/69145909/O1CN01a3RJxL1tWMrWo9G4q_!!69145909.png'],
			['name'=>'6宫4度','pic'=>'https://img.alicdn.com/imgextra/i2/69145909/O1CN01Q9U2601tWMrWoBKsz_!!69145909.png'],
			['name'=>'6宫4度','pic'=>'https://img.alicdn.com/imgextra/i2/69145909/O1CN01Q9U2601tWMrWoBKsz_!!69145909.png'],
			['name'=>'6宫8度','pic'=>'https://img.alicdn.com/imgextra/i3/69145909/O1CN01a3RJxL1tWMrWo9G4q_!!69145909.png'],
        ];
        return $list[$id-1];
    }
	
}
